<template>
    <tr>
      <th scope="row" v-show="!is_edit">{{ users.studentNumber }}</th>
      <td v-show="!is_edit">{{ users.name }}</td>
      <td v-show="!is_edit">{{ users.posts }}</td>
      <td v-show="!is_edit">{{ users.description }}</td>
      <td v-show="!is_edit">
          <el-button type="primary" icon="el-icon-edit" round @click="update">修改</el-button>
          <el-button type="danger" icon="el-icon-delete" round @click="open" >删除</el-button>
      </td>
      
      <th scope="row" v-show="is_edit"><input class="w-25" type="text" v-model.number="users.studentNumber"/></th>
      <td v-show="is_edit"><input type="text" class="w-50" v-model="users.name"/></td>
      <td v-show="is_edit"><input type="text" class="w-50" v-model="users.posts"/></td>
      <td v-show="is_edit"><input type="text" class="w-50" v-model="users.description"/></td>
      <td v-show="is_edit">
          <el-button type="success" round @click="save">保存</el-button>
          <el-button type="danger" round>删除</el-button>
      </td>
      <!-- <td v-show="is_edit">
          
      </td> -->
    </tr>
  </template>
  
  <script>
  import axios from 'axios'
  
  export default {
    props: ["users"],
   
    data() {
      return {
        is_edit: false,
        dialogVisible: false ,
        dialogTableVisible: false,
      }
    },
    // components() {
    //   // App
    // },
    methods: {
      handleClose(done) {
          this.$confirm('确认关闭？')
            .then(_ => {
              done();
            })
            .catch(_ => {});
        },
      update() {
        this.is_edit = true;
      },
      save() {
        axios({
          url: "http://localhost:8080/user/update",
          method: "Post",
          data: this.users
        })
        this.is_edit =false;
      },
      del() {
        axios({
          url: "http://localhost:8080/user/delete",
          method: "Post",
          data: this.users
        }).then(() => {
          this.dialogVisible = false;
          location.reload();
        })
      },
      open() {
          this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
          }).then(() => {
            this.del();
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
        }
    }
  }
  </script>
  
  <style>
  
  </style>